package leetcode.od;

import org.junit.Test;

/**
 * @author pppppp
 * @date 2022/3/30 11:44
 * 1,0,1,1,0,1,1,1表示停车位的情况，
 * 1表示有车，0表示空位，有三种车，分别占1,2,3个宽度的车位，求最少有几辆车，像上面这种情况，就是3辆车。
 */
public class 停车问题 {
    @Test
    public void T_0(){
      String []s = {"10110111","101101111","100001100001111","101001101001111","1111111"};
      int[]ans = {3,4,4,6,3};
        for (int i = 1; i < s.length; i++) {
            System.out.println(minCarNums(s[i]) == ans[i]);
        }
    }

    private int minCarNums(String s) {
        String[] split = s.replaceAll("0+", "0").split("0");
        int cnt = 0;
        for (String s1 : split) {
            if(s1.length()< 4){
                cnt++;
            }else {
                int len = s1.length();
                cnt += len/3;
                cnt += len % 3 == 0 ? 0:1;
            }
        }
        return cnt;
    }
}
